/*
 *此javaCode由YMS-JDBC替换工具生成，原mapper位置com.yonyou.ucf.mdf.app.isvdxq.other.mapper.SuiteauthMapper
 */
package com.yonyou.ucf.mdf.app.isvdxq.other.mapper.impl;

import com.yonyou.iuap.yms.api.IYmsJdbcApi;
import com.yonyou.iuap.yms.param.*;
import com.yonyou.iuap.yms.param.ResultSetProcessor;
import com.yonyou.iuap.yms.processor.*;
import com.yonyou.iuap.yms.replace.CollectionUtil;
import com.yonyou.ucf.mdf.app.isvdxq.firstpart.appconfig.entity.AppconfigEntity;
import com.yonyou.ucf.mdf.app.isvdxq.other.entity.SuiteauthEntity;
import java.sql.Types;
import java.util.*;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Repository;

@Repository
public class SuiteauthMapperImpl  {
    
    @Autowired
    private IYmsJdbcApi ymsJdbcApi;
    //com.yonyou.ucf.mdf.app.isvdxq.other.mapper.SuiteauthMapper.selectCountByKey
    
    public SuiteauthEntity selectCountByKey(String tenantId, String appkey) {
        SQLParameter parameter = new SQLParameter(true);
        
        String sql = "select * from dxq_suiteauth where `ytenant_id`=? and `suiteKey`=? limit 1;\n";
        parameter.addParam(tenantId);
		parameter.addParam(appkey);

        ResultSetProcessor processor = new AutoBeanProcessor(new SuiteauthEntity());
        return (SuiteauthEntity) ymsJdbcApi.queryForObject(sql, parameter, processor);
    }

    //com.yonyou.ucf.mdf.app.isvdxq.other.mapper.SuiteauthMapper.selectByCusToken
    
    public SuiteauthEntity selectByCusToken(String access_token) {
        SQLParameter parameter = new SQLParameter(true);
        
        String sql = "select * from dxq_suiteauth where `dxqToken`=? limit 1;\n";
        parameter.addParam(access_token);

        ResultSetProcessor processor = new AutoBeanProcessor(new SuiteauthEntity());
        return (SuiteauthEntity) ymsJdbcApi.queryForObject(sql, parameter, processor);
    }

    //com.yonyou.ucf.mdf.app.isvdxq.other.mapper.SuiteauthMapper.insert
    
    public int insert(SuiteauthEntity record) {
        SQLParameter parameter = new SQLParameter(true);
        
        String sql = "insert into dxq_suiteauth (`id`, `ytenant_id`, `suiteKey`,`suiteSecret`, `gatewayUrl`, `tokenUrl`,  `accessToken`, `expireAt`, `dxqToken`,  `ticket`, `userid`, `tenantName`, `editTime`) values (?, ?,  ?,?, ?, ?,  ?, ?, ?,  ?, ?, ?, ?)\n";
        parameter.addParamWithType(record.getId(), Types.INTEGER);
		parameter.addParamWithType(record.getTenant_id(), Types.VARCHAR);
		parameter.addParamWithType(record.getSuiteKey(), Types.VARCHAR);
		parameter.addParamWithType(record.getSuiteSecret(), Types.VARCHAR);
		parameter.addParamWithType(record.getGatewayUrl(), Types.VARCHAR);
		parameter.addParamWithType(record.getTokenUrl(), Types.VARCHAR);
		parameter.addParamWithType(record.getAccessToken(), Types.VARCHAR);
		parameter.addParamWithType(record.getExpireAt(), Types.VARCHAR);
		parameter.addParamWithType(record.getDxqToken(), Types.VARCHAR);
		parameter.addParamWithType(record.getTicket(), Types.VARCHAR);
		parameter.addParamWithType(record.getUserid(), Types.VARCHAR);
		parameter.addParamWithType(record.getTenantName(), Types.VARCHAR);
		parameter.addParamWithType(record.getEditTime(), Types.VARCHAR);

        
        return ymsJdbcApi.update(sql, parameter);
    }

    //com.yonyou.ucf.mdf.app.isvdxq.other.mapper.SuiteauthMapper.selectByToken
    
    public SuiteauthEntity selectByToken(String access_token) {
        SQLParameter parameter = new SQLParameter(true);
        
        String sql = "select * from dxq_suiteauth where `accessToken`=? limit 1;\n";
        parameter.addParam(access_token);

        ResultSetProcessor processor = new AutoBeanProcessor(new SuiteauthEntity());
        return (SuiteauthEntity) ymsJdbcApi.queryForObject(sql, parameter, processor);
    }

    //com.yonyou.ucf.mdf.app.isvdxq.other.mapper.SuiteauthMapper.selectById
    
    public SuiteauthEntity selectById(int id) {
        SQLParameter parameter = new SQLParameter(true);
        
        String sql = "select * from dxq_suiteauth where `id`=?;\n";
        parameter.addParam(id);

        ResultSetProcessor processor = new AutoBeanProcessor(new SuiteauthEntity());
        return (SuiteauthEntity) ymsJdbcApi.queryForObject(sql, parameter, processor);
    }

    //com.yonyou.ucf.mdf.app.isvdxq.other.mapper.SuiteauthMapper.updateByTenantId
    
    public int updateByTenantId(String accessToken, String expireAt, String userid, String tenant_id) {
        SQLParameter parameter = new SQLParameter(true);
        
        String sql = "update dxq_suiteauth set `accessToken` = ?, `expireAt` = ?, `userid` = ? where `ytenant_id` = ?\n";
        parameter.addParamWithType(accessToken, Types.VARCHAR);
		parameter.addParamWithType(expireAt, Types.VARCHAR);
		parameter.addParamWithType(userid, Types.VARCHAR);
		parameter.addParamWithType(tenant_id, Types.VARCHAR);

        
        return ymsJdbcApi.update(sql, parameter);
    }

    //com.yonyou.ucf.mdf.app.isvdxq.other.mapper.SuiteauthMapper.selectAll
    
    public List<SuiteauthEntity> selectAll() {
        SQLParameter parameter = new SQLParameter(true);
        
        String sql = "select * from dxq_suiteauth ;\n";
        
        ResultSetProcessor processor = new AutoBeanListProcessor(new SuiteauthEntity());
        return (List<SuiteauthEntity>) ymsJdbcApi.queryForList(sql, parameter, processor);
    }

    //com.yonyou.ucf.mdf.app.isvdxq.other.mapper.SuiteauthMapper.selectByTenantId
    
    public List<SuiteauthEntity> selectByTenantId(String tenantId) {
        SQLParameter parameter = new SQLParameter(true);
        
        String sql = "select * from dxq_suiteauth where `ytenant_id`=?;\n";
        parameter.addParam(tenantId);

        ResultSetProcessor processor = new AutoBeanListProcessor(new SuiteauthEntity());
        return (List<SuiteauthEntity>) ymsJdbcApi.queryForList(sql, parameter, processor);
    }

    //com.yonyou.ucf.mdf.app.isvdxq.other.mapper.SuiteauthMapper.updateByPrimaryKey
    
    public int updateByPrimaryKey(SuiteauthEntity record) {
        SQLParameter parameter = new SQLParameter(true);
        
        String sql = "update dxq_suiteauth set `ytenant_id` = ?, `suiteKey` = ?, `suiteSecret` = ?, `gatewayUrl` = ?, `tokenUrl` = ?, `accessToken` = ?, `expireAt` = ?, `ticket` = ?, `userid` = ?, `tenantName` = ?, `editTime` = ?, `dxqToken` = ? where `id` = ?\n";
        parameter.addParamWithType(record.getTenant_id(), Types.VARCHAR);
		parameter.addParamWithType(record.getSuiteKey(), Types.VARCHAR);
		parameter.addParamWithType(record.getSuiteSecret(), Types.VARCHAR);
		parameter.addParamWithType(record.getGatewayUrl(), Types.VARCHAR);
		parameter.addParamWithType(record.getTokenUrl(), Types.VARCHAR);
		parameter.addParamWithType(record.getAccessToken(), Types.VARCHAR);
		parameter.addParamWithType(record.getExpireAt(), Types.VARCHAR);
		parameter.addParamWithType(record.getTicket(), Types.VARCHAR);
		parameter.addParamWithType(record.getUserid(), Types.VARCHAR);
		parameter.addParamWithType(record.getTenantName(), Types.VARCHAR);
		parameter.addParamWithType(record.getEditTime(), Types.VARCHAR);
		parameter.addParamWithType(record.getDxqToken(), Types.VARCHAR);
		parameter.addParamWithType(record.getId(), Types.INTEGER);

        
        return ymsJdbcApi.update(sql, parameter);
    }

    //com.yonyou.ucf.mdf.app.isvdxq.other.mapper.SuiteauthMapper.insertBatch
    
    public int insertBatch(List<AppconfigEntity> insertBatch) {
        SQLParameter parameter = new SQLParameter(true);
        StringBuilder sqlBuilder = new StringBuilder();
		sqlBuilder.append(" insert into isv_appconfig (`id`, `ytenant_id`, `appType`,`appCode`, `applicationId`, `localservurl`, `status`, `dr`, `create_time`, `modify_time`, `creator`, `creatorName`, `modifier`, `modifierName`, `pubts`, `version`) values ");
		if (CollectionUtil.isNotEmpty(insertBatch)) {
			String separator0 = " , ";
			for (int i = 0; i < insertBatch.size(); i++) {
				AppconfigEntity item = insertBatch.get(i);
				sqlBuilder.append(" (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) ");
				parameter.addParamWithType(item.getId(), Types.BIGINT);
				parameter.addParamWithType(item.getTenant_id(), Types.BIGINT);
				parameter.addParamWithType(item.getAppType(), Types.INTEGER);
				parameter.addParamWithType(item.getAppcode(), Types.VARCHAR);
				parameter.addParamWithType(item.getApplicationid(), Types.VARCHAR);
				parameter.addParamWithType(item.getLocalservurl(), Types.VARCHAR);
				parameter.addParamWithType(item.getStatus(), Types.INTEGER);
				parameter.addParamWithType(item.getDr(), Types.SMALLINT);
				parameter.addParamWithType(item.getCreateTime(), Types.VARCHAR);
				parameter.addParamWithType(item.getModifyTime(), Types.VARCHAR);
				parameter.addParamWithType(item.getCreator(), Types.VARCHAR);
				parameter.addParamWithType(item.getCreatorname(), Types.VARCHAR);
				parameter.addParamWithType(item.getModifier(), Types.VARCHAR);
				parameter.addParamWithType(item.getModifiername(), Types.VARCHAR);
				parameter.addParamWithType(item.getPubts(), Types.TIMESTAMP);
				parameter.addParamWithType(item.getVersion(), Types.INTEGER);
				if (i < insertBatch.size() - 1) {
					sqlBuilder.append(separator0);
				}
			}
		}
		sqlBuilder.append(" ON DUPLICATE KEY UPDATE appcode=VALUES(appcode),applicationid=VALUES(applicationid),localservurl=VALUES(localservurl) ,modifiername=VALUES(modifiername),modifier=VALUES(modifier) ");

        
        String sql = sqlBuilder.toString();
        
        return ymsJdbcApi.update(sql, parameter);
    }

    //com.yonyou.ucf.mdf.app.isvdxq.other.mapper.SuiteauthMapper.selectCount
    
    public int selectCount(int id) {
        SQLParameter parameter = new SQLParameter(true);
        
        String sql = "select count(1) from dxq_suiteauth where `id`=?;\n";
        parameter.addParam(id);

        ResultSetProcessor processor = new ColumnProcessor(int.class);
        return (int) ymsJdbcApi.queryForObject(sql, parameter, processor);
    }

    //com.yonyou.ucf.mdf.app.isvdxq.other.mapper.SuiteauthMapper.deleteByPrimaryKey
    
    public int deleteByPrimaryKey(int id) {
        SQLParameter parameter = new SQLParameter(true);
        
        String sql = "delete from dxq_suiteauth where `id` = ?\n";
        parameter.addParamWithType(id, Types.INTEGER);

        
        return ymsJdbcApi.update(sql, parameter);
    }

    //com.yonyou.ucf.mdf.app.isvdxq.other.mapper.SuiteauthMapper.selectByTenantIds
    
    public List<SuiteauthEntity> selectByTenantIds(List<String> strList) {
        SQLParameter parameter = new SQLParameter(true);
        StringBuilder sqlBuilder = new StringBuilder();
		sqlBuilder.append(" select * from dxq_suiteauth where `ytenant_id` in ");
		if (CollectionUtil.isNotEmpty(strList)) {
			sqlBuilder.append(" ( ");
			String separator0 = " , ";
			for (int index = 0; index < strList.size(); index++) {
				String item = strList.get(index);
				sqlBuilder.append(" ? ");
				parameter.addParam(item);
				if (index < strList.size() - 1) {
					sqlBuilder.append(separator0);
				}
			}
			sqlBuilder.append(" ) ");
		}else{
            sqlBuilder.append(" ( '' )");
        }
		sqlBuilder.append(" ; ");

        
        String sql = sqlBuilder.toString();
        ResultSetProcessor processor = new AutoBeanListProcessor(new SuiteauthEntity());
        return (List<SuiteauthEntity>) ymsJdbcApi.queryForList(sql, parameter, processor);
    }

    //com.yonyou.ucf.mdf.app.isvdxq.other.mapper.SuiteauthMapper.SelectLastEntity
    
    public AppconfigEntity SelectLastEntity(String tenant_id, String appCode, Integer appType) {
        SQLParameter parameter = new SQLParameter(true);
        
        String sql = "select * from isv_appconfig   where appType = ? and appCode = ?  and ytenant_id=?  order by create_time desc limit 1\n";
        parameter.addParam(appType);
		parameter.addParam(appCode);
		parameter.addParam(tenant_id);

        ResultSetProcessor processor = new AutoBeanProcessor(new AppconfigEntity());
        return (AppconfigEntity) ymsJdbcApi.queryForObject(sql, parameter, processor);
    }

    public int EditrefreshTime(Integer refreshTime, String tenant_id){
        SQLParameter parameter = new SQLParameter(true);
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append("update dxq_suiteauth set refreshTime=? where tenant_id=?;");
        parameter.addParam(refreshTime);
        parameter.addParam(tenant_id);

        String sql = stringBuilder.toString();
        return ymsJdbcApi.update(sql, parameter);
    }
}
